<template>
    <div class='order'>
        <div class="container">
            <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" class="search-con">
                <!-- <el-form-item label="处理状态" prop="key_order_type" style="margin-right:25px;">
                    <el-select v-model="queryParams.key_order_type" placeholder="请选择" clearable size="small">
                        <el-option v-for="dict in statusList" :key="dict.dictValue" :label="dict.dictLabel"
                            :value="dict.dictValue" />
                    </el-select>
                </el-form-item> -->
                <el-col :span="24">
                    <el-form-item>
                        <el-button size="mini" v-for="item, index in btnList" :key="index" @click="changeTab(index)"
                            :type="curLine == index ? 'primary' : 'default'">
                            {{ item.dictLabel }}(0)</el-button>
                    </el-form-item>
                </el-col>
                <el-form-item label="输入搜索：" prop="key" style="margin-right:25px;">
                    <el-input v-model="queryParams.key" placeholder="服务单号" clearable size="small" />
                </el-form-item>
                <el-form-item label="收货人：" prop="key" style="margin-right:25px;">
                    <el-input v-model="queryParams.key" placeholder="收货人姓名/手机号码" clearable size="small" />
                </el-form-item>
                <el-form-item label="申请时间：" prop="key_range" style="margin-right:25px;">
                    <el-date-picker v-model="queryParams.key_range" type="daterange" range-separator="至"
                        start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" placeholder="请选择提交时间范围" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                    <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport"
                        v-hasPermi="['customer:manage:export']">导出
                    </el-button>
                </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8">
                <!-- <el-col :span="22">
                    <el-button type="primary" icon="el-icon-plus" size="mini" @click="title='新增';handleShow='add'" v-hasPermi="['user:depart:add']">
                        新增</el-button>
                </el-col> -->
                <el-col :span="22">
                    <el-button type="primary" icon="el-icon-edit" size="mini"
                        @click="handleBulk" v-hasPermi="['customer:manage:add']">
                        批量修改</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
            <el-table border v-loading="loading" :data="tableList" ref="tableList" v-tableHeight
                :height="tableList.length > 0 ? '900px' : '120px'" @selection-change="handleSelectionChange"
                @row-click="toggleSelection">
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column label="服务单号" align="center" prop="id" />
                <el-table-column label="申请时间" align="center" prop="time" />
                <el-table-column label="用户账号" align="center" prop="account" />
                <el-table-column label="退款金额" align="center" prop="amount" />
                <el-table-column label="联系人" align="center" prop="amount" />
                <el-table-column label="处理时间" align="center" prop="pay_way" />
                <el-table-column label="申请状态" align="center" prop="status">
                    <template slot-scope="scope">
                        <span>
                            {{ selectDictLabel(statusList, scope.row.status) }}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <el-button size="mini" type="text" icon="el-icon-document"
                            @click="title = '处理详情'; form = JSON.parse(JSON.stringify(scope.row)); handleShow = 'edit'"
                            v-hasPermi="['user:depart:edit']">
                            查看详情
                        </el-button>
                        <!-- <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                            v-hasPermi="['user:depart:del']">
                            删除</el-button> -->
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="pageCount > 0" :pageCount="pageCount" :page.sync="queryParams.page"
                :limit.sync="queryParams.limit" @pagination="getList" />
        </div>
        <el-dialog :title="title" visible v-if="handleShow" @close="close()" width="45%" append-to-body
            :close-on-click-modal="false">
            <el-form ref="form" :model="form" :rules="rules" label-width="120px" v-loading="formLoading">
                <el-row>
                    <el-descriptions class="margin-top decs" :column="2" :size="size" border>
                        <el-descriptions-item label="服务单号">
                            <el-form-item prop="id">
                                <span class="p">{{ form.id }}</span>
                            </el-form-item>
                        </el-descriptions-item>
                        <el-descriptions-item label="用户账号">
                            <el-form-item prop="account">
                                <span class="p">{{ form.account }}</span>
                            </el-form-item>
                        </el-descriptions-item>
                        <el-descriptions-item label="申请时间">
                            <el-form-item prop="time">
                                <span class="p">{{ form.time }}</span>
                            </el-form-item>
                        </el-descriptions-item>
                        <el-descriptions-item label="退款金额">
                            <el-form-item prop="account">
                                <span class="p">{{ form.account }}</span>
                            </el-form-item>
                        </el-descriptions-item>
                        <el-descriptions-item label="处理时间">
                            <el-form-item prop="account">
                                <span class="p">{{ form.account }}</span>
                            </el-form-item>
                        </el-descriptions-item>
                        <el-descriptions-item label="申请状态">
                            <el-form-item prop="account">
                                <span class="p">{{ form.account }}</span>
                            </el-form-item>
                        </el-descriptions-item>
                        <el-descriptions-item label="联系人">
                            <el-form-item prop="account">
                                <span class="p">{{ form.account }}</span>
                            </el-form-item>
                        </el-descriptions-item>
                    </el-descriptions>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="close()">确定</el-button>
                <!-- <el-button type="primary" @click="submit" :disabled="formLoading">确 定</el-button> -->
            </span>
        </el-dialog>
    </div>
</template>
<script>
import { getSectorLists, setSector, setSectorStatus, delSector } from "@/api/user/department.js"

import { departStatus } from "@/api/dictionary"

import throttle from 'lodash.throttle'
export default {
    name: 'order',
    props: {

    },
    data() {
        return {
            showSearch: true,
            loading: false,
            pageCount: 0,
            total: 0,
            queryParams: {
                page: 1,
                limit: 20,
                key: null,
            },
            tableList: [],
            statusList: departStatus,
            handleShow: "",
            formLoading: false,
            form: {
                id: null,
                name: null,
            },
            rules: {
                name: [{ required: true, message: '请输入部门名称', trigger: 'blur' }],
            },
            title: "",
            size: 'mini',
            curLine: 0,
            btnList: [
                {
                    dictLabel: '全部申请',
                    dictValue: 0
                },
                {
                    dictLabel: '待处理',
                    dictValue: 1
                },
                {
                    dictLabel: '退货中',
                    dictValue: 2
                },
                {
                    dictLabel: '已完成',
                    dictValue: 3
                },
                {
                    dictLabel: '已拒绝',
                    dictValue: 3
                }
            ],
        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList() {
            this.loading = true;
            getSectorLists(this.queryParams).then(res => {
                this.tableList = res.data.lists;
                this.pageCount = res.data.pageCount;
                this.loading = false;
            });
        },
        changeTab(index) {
            this.curLine = index
            this.getList()
        },
        handleQuery() {
            this.queryParams.page = 1;
            this.getList();
        },
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        toggleSelection(row) {
            this.$refs.tableList.toggleRowSelection(row);
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.selectData = selection;
        },
        handleBulk(ids) {
            this.$confirm('是否确认批量修改?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return delSector({ id: row.id });
            }).then(() => {
                this.getList();
                this.msgSuccess("修改成功");
            })
        },
         /** 导出按钮操作 */
         handleExport() {
                const queryParams = this.queryParams;
                this.$confirm('是否确认导出所有数据项?', '警告', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {
                    // return exportBanner(queryParams);
                }).then((response) => {
                    // this.download(response.msg);
                });
            },
        close() {
            this.form = {}
            this.handleShow = ""
        },
        handleAble(row) {
            // let label = row.status == 0 ? '停用' : '启用';
            this.$confirm(`是否将“${row.name}”关闭?`, "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return setSectorStatus({ id: row.id });
            }).then(() => {
                this.getList();
                this.msgSuccess(`${label}成功`);
            })
        },
        handleDelete(row) {
            this.$confirm('是否确认删除' + '"' + row.name + '"' + '?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return delSector({ id: row.id });
            }).then(() => {
                this.getList();
                this.msgSuccess("删除成功");
            })
        },

        submit: throttle(function () {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.formLoading = true;
                    setSector(this.form).then(res => {
                        this.msgSuccess("操作成功！");
                        this.close()
                        this.formLoading = false;
                        this.getList();
                    }).catch(() => {
                        this.formLoading = false;
                    })
                }
            })
        }, 1000, { trailing: false }),
    }
}
</script>

<style lang='scss' scoped>
.decs {

    /deep/.el-descriptions--mini.is-bordered .el-descriptions-item__cell {
        padding: 0 10px;
    }

    /deep/.el-descriptions-item__cell {
        padding-left: 8px;
        font-size: 14px;
    }

    /deep/ .el-col {
        margin: 0px;
        padding: 0px;
        height: 30px;
        line-height: 30px;
    }

    /deep/.el-form-item__error {
        top: 21%;
        right: 5% !important;
        left: unset;
    }
}

.p {
    font-size: 14px;
}</style>
